Es6 模块的导入和导出

b.js

1
2
3
4
5
6
7
8
export function fun(){
console.log("fun1")
}

export let person = {
name:"devin",
age:12
}

c.js

1
2
3
4
5
6
7
8
let a = 12
let fun = function(){
console.log("function")
}

export default{
a,fun
}

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script type="module" >
// import * as util from './a.js';
// //import {fun, person} from "./a.js";
// console.log(util.fun(),util.person)
// import a from './exportDefault';
// a.show();
// console.log(a.a);

// import * as util from "./b.js"
import c from "./c.js"
// console.log(util.fun)
console.log(c.a)
c.fun()

</script>
</body>
</html>
Donate comment here